﻿using db_manage.dll.common;
using db_manage.dll.manage;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace db_manage.page
{
    public partial class form_detach_attach : Form
    {
        private static form_db_info form_db_info { get => manage.from_get<form_db_info>(); }

        public form_detach_attach()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 分离路径
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_detach_path_Click(object sender, EventArgs e)
        {
            if (fbd_path.ShowDialog() == DialogResult.OK)
            {
                tb_detach_path.Text = fbd_path.SelectedPath;
            }
        }

        /// <summary>
        /// 附加路径
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_attach_path_Click(object sender, EventArgs e)
        {
            if (fbd_path.ShowDialog() == DialogResult.OK)
            {
                tb_attach_path.Text = fbd_path.SelectedPath;
            }
        }

        /// <summary>
        /// 分离
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_detach_Click(object sender, EventArgs e)
        {
            if (!manage.isAdmin())
            {
                MessageBox.Show("请用管理员权限打开");
                return;
            }
            var dir = tb_detach_path.Text.Trim();
            if (string.IsNullOrEmpty(dir))
            {
                MessageBox.Show("请填写分离后保存目录");
                return;
            }
            //创建分离目录
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            MessageBox.Show("开始操作,请不要关闭窗口");
            form_db_info.ShowAndBringToFront();
            MessageBox.Show(manage.detach(dir));
        }

        /// <summary>
        /// 附加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_attach_Click(object sender, EventArgs e)
        {
            var dir = tb_attach_path.Text.Trim();
            if (string.IsNullOrEmpty(dir))
            {
                MessageBox.Show("请填写附加目录");
                return;
            }
            MessageBox.Show("开始操作,请不要关闭窗口");
            form_db_info.ShowAndBringToFront();
            MessageBox.Show(manage.attach(dir));
        }
    }
}
